import time

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

from common.Base import Base
from day8.autoframe.common.functions import open_browser


class LoginPage(Base):
    login_url = 'http://139.129.26.163/user.php'


    def input_username(self, username):
       self.find_element((By.NAME, "username")).send_keys(username)

    def input_password(self, password):
        self.find_element((By.NAME,"password")).send_keys(password)
    #定位登录按钮
    def login(self):
        self.click((By.CLASS_NAME,"us_Submit"))
   #定位弹窗窗口
    def alert(self):
        alert = self.driver.switch_to.alert
        alert.accept()

        # 定位服装按钮
    def click_fz(self):
        self.click((By.LINK_TEXT, '服装'))

    #定位移动电源
    def click_yddy(self):
        self.click((By.LINK_TEXT, '移动电源'))

        # 点击首页按钮
    def home_page_click(self):
        self.click((By.CLASS_NAME, 'cur'))

   #定位立即购买按钮
    def click_buy(self):
         self.click((By.CLASS_NAME, 'td1'))
    #定位收藏按钮
    def click_ction(self):
         self.click((By.CLASS_NAME, 'td2'))
    #定位购物车按钮
    def click_shopping(self):
        self.click((By.ID, 'ECS_CARTINFO'))
    #定位清空购物车按钮
    def click_qkshopping(self):
        self.click((By.XPATH, "//input[@value='清空购物车']"))
    #定位更新购物车按钮
    def click_gxshopping(self):
        self.click((By.XPATH, "//input[@value='更新购物车']"))
    #定位继续购物按钮
    def click_jxshopping(self):
        self.click((By.XPATH, "//*[@alt='continue']"))
    #定位到去结算按钮
    def click_jsshopping(self):
        self.click((By.XPATH, "//*[@alt='checkout']"))
    #定位删除键
    def backspace(self,locator,vlues):
        element = self.find_element(locator)
        element.send_keys(Keys.BACKSPACE)
        element.send_keys(vlues)











if __name__ == '__main__':
    browser = open_browser()
    login = LoginPage(browser)
    login.get('http://139.129.26.163/user.php')
    time.sleep(2)
    login.input_username("zxc123889")
    login.input_password("123456")
    login.login()
    login.quit(2)






















